package com.wyb.springcloud.demo.eurekaconsumerfeignhystrix.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.Charset;
import java.util.Base64;

@Configuration
public class FeignConfig implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        //添加 hedaer
        String auth = "admin:123456";

        byte[] encodeAuth = Base64.getEncoder().encode(auth.getBytes(Charset.forName("US-ASCII")));
        String headerValue = "Basic "+ new String(encodeAuth);
        requestTemplate.header("Authorization", headerValue);
    }
}
